package com.wandian.texas.command.texas;

import java.util.Date;

import com.wandian.texas.BaseCommandObject;
import com.wandian.texas.CommandObject;
import com.wandian.texas.GameData;
import com.wandian.texas.UserMgr;
import com.wandian.command.Cmd;
import com.wandian.command.UserCommand;
import com.wandian.texas.db.DaoManager;
import com.wandian.texas.protocol.Protocol;
import com.wandian.util.DateUtil;
import com.wandian.util.Log;

@Cmd(code = 10000, desc = "")
public class TestAutoAddCmd extends UserCommand {

	@Override
	public void execute(BaseCommandObject cmdObject) {
		super.execute(cmdObject);
		byte flag = cmdObject.readByte();
		if (flag == 0) {
			long start = System.currentTimeMillis();
			GameData.STARTTIME = start;
			Log.info("测试test表自动增加开始:" + DateUtil.format(new Date(start)));
		} else if (flag == 2) {
			long end = System.currentTimeMillis();
			// GameData.STOPTIME=end;
			Log.info("测试test表自动增加开结束:" + DateUtil.format(new Date(end)) + "消耗时间：ms" + (end - GameData.STARTTIME));
		}
		int count = DaoManager.TestDao(cmdObject.dbIndex).ReturnAutoAddCount();
//		System.out.println(count);
		cmdObject.setCmd(Protocol.CHATROOM_SEND_MESSAGE);
		cmdObject.writeBegin();
		cmdObject.writeString(cmdObject.getUser().getRealName());
		cmdObject.writeByte((byte) 0);
		cmdObject.writeString(String.valueOf(count));
		cmdObject.writeEnd();
		UserMgr.I().SendData(cmdObject.sessionObject,cmdObject);
		// System.out.println(String.format("更新测试表 [%s]", result?"成功":"失败"));
	}

	class DelaySendCommand implements Runnable {
		CommandObject cmdObject;
		String message;
		int delay;

		public DelaySendCommand(CommandObject _cmdObject, String _message, int _delay) {
			cmdObject = _cmdObject;
			message = _message;
			delay = _delay;
		}

		public void run() {
			cmdObject.setCmd((short) 8000);
			cmdObject.writeBegin();
			cmdObject.writeString("系统:");
			cmdObject.writeByte((byte) 0);
			cmdObject.writeString("这是服务器延时返回的信息,延时" + delay + "000毫秒,内容:" + message);
			cmdObject.writeEnd();
			UserMgr.I().SendData(cmdObject.sessionObject,cmdObject);
		}

	}
}
